<%--
  Created by IntelliJ IDEA.
  User: 29012
  Date: 2021/11/2
  Time: 18:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor/ueditor.all.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor/lang/zh-cn/zh-cn.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/ueditor/themes/iframe.css">
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width:850px;
            /*height: 800px;*/
            margin: 0 auto;
        }
    </style>
</head>
<body>

<h1>写文章</h1>
<input type="text" class="articleName" placeholder="请输入文章标题">

<!--style给定宽度可以影响编辑器的最终宽度-->
<script  name="content" type="text/plain" id="content">
</script>
<button onclick="getAllHtml()">提交</button>



<script type="text/javascript">
    var ue = UE.getEditor('content')
    ue.ready(function (){
        ue.setHeight(800)
    })
    var articleContent
    var articleName
    function getAllHtml() {
        articleContent = UE.getEditor('content').getAllHtml();
        articleName = $(".articleName").val();
        if (articleName == ""){
            articleName = "请输入文章标题"
        }
        $.post("${pageContext.request.contextPath}/community/saveArticle",
            {"articleName":articleName,
                "articleContent":articleContent,
                "articleDatetime":new Date()},
            function (e){
                if (e > 0){
                    alert("保存成功！")
                    location.href = "${pageContext.request.contextPath}/community?label=推荐";
                }else {
                    alert("保存失败！")
                }
            },
            "json"
        )
    }
</script>


</body>
</html>
